/**
 * Created by chang on 2017/8/30.
 */
$("#keep").click(function () {
    var sendCodeOK = $('#sendCode').val();//验证码
    var phoneTextOK = $('#phoneText').val();//手机号
    var pasWOK = $('#pasW').val();//确认新密码
    var pasWone = $('#pasWone').val();//新密码
    $("#mask").css("display","none");
    $("#all-error").css("display", "none");
    if (sendCodeOK == "" || phoneTextOK == "" || pasWOK == "" || pasWone == "") {
        $("#all-error").css("display", "block");
        $("#all-error").html("所有项不能为空");
        return false;
    } else {
        var arr = {};

        Ajax(1,'/api/user/update','post',JSON.stringify(arr)).then(function (r) {
            if (r.code==0){
                if(arr.sex == 0){
                    $('#sex').text('性別：女');
                }else if(arr.sex == 1){
                    $('#sex').text('性別：男');
                }
                $(".personal-name").html(arr.nikeName);
                $('#username').text('昵称：'+ arr.nikeName);
                $('#birthday').text('生日：'+ arr.birthday)
            }
            $("input[type='sex']").removeAttr('checked');
        });
        $.ajax({
            url: BaseUrl+ "/api/register",
            type: "post",
            data: {
                mobile: phoneTextOK,
                code: sendCodeOK,
                password: pasWone,
                password1: pasWOK
            },
            success: function (response) {
                console.log(response.msg);
                console.log(response.code);
                if (response.code == 0) {
                    location.href = 'login.html';
                    // console.log("code的值");
                } else if (response.code == 103) {
                    alert("user has been registered, please login ahead !");
                    location.href = 'login.html';
                }
            },
            error: function () {
                alert("系统繁忙，请稍后再试...");
            }
        });
    }
});
